package com.compass.doctor.ui.home.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.compass.doctor.callback.OnCustomButtonClick
import com.compass.doctor.databinding.LayoutDoctorItemBinding
import com.compass.doctor.databinding.LayoutDoctorReferralItemBinding
import com.compass.framework.adapter.BaseBindViewHolder
import com.compass.framework.adapter.BaseMultiItemAdapter
import com.compass.framework.ext.saveAs
import com.compass.framework.glide.seCircletUrl
import com.compass.framework.model.Doctor

/**
 * Description： 医生adapter
 * Date:2023/12/12 16:27
 */

class DoctorAdapter constructor(private var itemType: Int) :
    BaseMultiItemAdapter<Doctor>() {

    private lateinit var onChatBottomClick: OnCustomButtonClick

    //用来实现多item布局
    override fun getDefItemViewType(position: Int): Int {
        return itemType
    }

    fun setBottomCallBack(onChatBottomClick: OnCustomButtonClick) {
        this.onChatBottomClick = onChatBottomClick
    }

    override fun onBindDefViewHolder(
        holder: BaseBindViewHolder<ViewBinding>,
        item: Doctor?,
        position: Int
    ) {
        if (item == null) return
        //  //1、会诊医生列表，else 转诊医生列表
        when (itemType) {
            1 -> {
                val binding = holder.binding.saveAs<LayoutDoctorItemBinding>()
                binding.apply {
                    tvDoctorName.text = item.name
                    imgDoctorHead.seCircletUrl(item.avatar)
                    tvPositionName.text = item.positionName
                    tvDepartmentName.text = item.departmentName
                    tvHospitalName.text = item.hospitalName
                    tvCount.text="${item.medicalConsultationCount}次会诊"
                }
            }

            else -> {
                val binding = holder.binding.saveAs<LayoutDoctorReferralItemBinding>()
                binding.apply {
                    tvDoctorName.text = item.name
                    imgDoctorHead.seCircletUrl(item.avatar)
                    tvDepartmentName.text = item.departmentName
                    tvHospitalName.text = item.hospitalName
                    tvPositionName.text = item.positionName?:"暂无职称"
                    tvPrice.text ="￥${item.consultationPrice}"
                }

            }
        }

    }



    override fun getViewBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): ViewBinding {
        return when (viewType) {
            1 -> {
                LayoutDoctorItemBinding.inflate(layoutInflater, parent, false)
            }

            else -> {
                LayoutDoctorReferralItemBinding.inflate(layoutInflater, parent, false)
            }
        }

    }
}